/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenAgeRange implements Generalisator{
    private int defaultRange = 10;
    
    public GenAgeRange(){
    }
    
    @Override
    public String gen(String value){
        if(value.equals("0-100")||value.equals("*"))
            return "0-100";
        String result;
        String[] nb = value.split("-");
        if(nb.length==1){ // it is a number
            int v = Integer.valueOf(nb[0]);
            v/=defaultRange;
            v*=defaultRange;
            result=(v)+"-"+(v+defaultRange);
        }else{
            int v1 = Integer.valueOf(nb[0]);
            int v2 = Integer.valueOf(nb[1]);
            int range = (v2-v1)*2;
            if(range>20)
                return "*";
            v1/=range;
            v1*=range;
            v2 = v1+range;
            result=(v1)+"-"+(v2);
        }
        
        return result;
    }
    
    @Override
    public int getMaxGeneralisation() {
        return 4;
    }
    
    @Override
    public double getLength(String value){
        if(value.equals("*"))
            return 100.0;
        int result=1;
        String[] nb = value.split("-");
        if(nb.length==2){
            int v1 = Integer.valueOf(nb[0]);
            int v2 = Integer.valueOf(nb[1]);
            result=v2-v1;
        }
        return result;
    }
    
    @Override
    public double getMaxLength(){
        return 100.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        return "";
    }

    @Override
    public int getGeneralisationLevel(String value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
